<?php

// +----------------------------------------------------------------------
// | 权限组控制器
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2024 http://www.yicmf.com, All rights reserved.
// +----------------------------------------------------------------------
// | Author: 微尘 <yicmf@qq.com>
// +----------------------------------------------------------------------

namespace app\controller\pos\admin;

use app\model\pos\PosTrade as PosTradeModel;
use app\model\pos\Pos as PosModel;
use yicmf\builder\Edit;
use yicmf\builder\Table;
use app\controller\admin\Common;
use yicmf\builder\View;

class PosTrade extends Common
{
    protected function initialize()
    {
        parent::initialize(); 
    }

    public function _filter()
    {
        $where[] = ['status', '>', -2];
        return $where;
    }

    public function index()
    {
        $where = $this->_filter();
        // ID 商户编号 商户名称  机具序列号 品牌 交易金额 交易状态 交易类型 支付渠道 流水号 交易日期
        //交易状态：交易成功 交易失败
        //交易类型：刷卡 扫码
        //支付渠道：贷记卡 借记卡 微信 支付宝 云闪付等
        $builder = new Table();
        $builder->model(PosTradeModel::class)
            ->where($where)
            ->order('id DESC')
//                ->suggest('高等级可以对低等级用户进行操作或者授权')
            ->searchText('pos_sn', 'pos序列号')
//            ->buttonUpdate('update','划转')
            ->keyId()
//            ->keyTitle('标签名称')
            ->keyText('merch_no','商户编号')
            ->keyText('store.nickname','商户名称')
            ->keyUser('user_id','合伙人')
            ->keyText('pos_sn','机具序列号')
            ->keyMap('channel_id','品牌',PosModel::$channel)
            ->keyText('amount','交易金额')
            ->keyMap('status','交易状态',['失败','成功'])//易成功 交易失败
//            ->keyText('pos_num','交易类型')//刷卡 扫码
            ->keyMap('card_type','卡类型',['','借记卡','借贷卡'])//贷记卡 借记卡 微信 支付宝 云闪付等
            ->keyMap('trade_type','交易类型',['','刷卡','扫码'])//1刷卡2扫码
            ->keyText('trans_sn','流水号')
            ->keyText('trans_time','交易日期')
//            ->actionView()
        ;
        return $builder->fetch();
    }

//
//    public function update()
//    {
//        if ($this->request->isPost()) {
//           $event = new \app\event\pos\PosTrade();
//           $data = $event->gift($this->request->param(),$this->user);
//            if (0 === $data['code']) {
//                $this->_returnSuccess($data['message']);
//            } else {
//                $this->_returnError($data['message'], false);
//            }
//        } else {
//            // 同步节点与菜单
//
//            $data = [];
//            $vips = \app\model\pos\PosLevel::where('status',1)->column('title','id');
//            $data['pos_level_id'] = array_key_first($vips);
//                $builder = new Edit();
//                $builder->title('新增划转')
//                    ->keyTextInline('username', '接收会员账号')
//                    ->keyTextInline('name','pos名称')
//                    ->keyTextInline('model','pos型号')
//                    ->keyTextArea('pos_sn','pos序列号','pos机序列号，每行一个。')
//                    ->data($data)
//                    ->buttonSubmit();
//                return $builder->fetch();
//        }
//    }

    public function view()
    {

        $data = PosTradeModel::where('id', $this->request->param('id'))->find();

        $data['pos_sns'] = implode(' ', $data['pos_sn']);
                $builder = new View();
                $builder->title('划转详情')
                    ->keyLabel('pos_level.title','划赠VIP')
                    ->keyLabel('pos_num', '划转数量', '');


        $builder->keyLabel('pos_sns', '划转序列号', '')
                    ->keyLabel('create_time', '划转时间', '')
                    ->data($data);
                return $builder->fetch();
    }


}
